import { reactive, ref } from "vue";

interface IResModel {
    list: any;    //列表
    total: number; //总条数
}

export default function umsTable<P, R extends IResModel>(reqAPI: (params: P) => RES<R>, serachVal: P) {
    const tabList = ref<R["list"]>([])
    const paginationParams = reactive({
        currentPage: 1,
        pageSize: 10,
        total: 20
    })
    const getAdminList = () => {
        reqAPI({
            pageNum: paginationParams.currentPage,
            pageSize: paginationParams.pageSize,
            ...serachVal
        }).then((res) => {
            tabList.value = res.data.list
            paginationParams.total = res.data.total
        })
    }
    getAdminList()

    const handleSizeChange = (val: number) => {
        paginationParams.pageSize = val
        getAdminList()
    }
    const handleCurrentChange = (val: number) => {
        paginationParams.currentPage = val
        getAdminList()
    }

    return {
        tabList,
        paginationParams,
        handleSizeChange,
        handleCurrentChange,
        getAdminList
    }
}